package com.xbongbong.pro.enums.menu.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.MenuTypeEnum;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

@Getter
public enum ProductPriceMenuEnum {

    // 产品价目查询
    PRICE_PRODUCT("enum.productMenu.name.price_product", XbbRefTypeEnum.PRICE_SET_PRODUCT.getAlias(), XbbRefTypeEnum.PRICE_SET_PRODUCT.getCode(), AccessLinkEnum.PRICE_PRODUCT, "", MenuTypeEnum.FORM.getType()),

    ;
    /**
     * saas应用标示解释
     */
    private final String name;
    /**
     * saas应用标示
     *
     * @see XbbRefTypeEnum
     */
    private final String alias;
    /**
     * @see XbbRefTypeEnum
     */
    private final Integer code;
    /**
     * 对应的链接
     */
    private final AccessLinkEnum accessLinkEnum;

    /**
     * 父节点，如果没有父节点，则此值为空字符串
     */
    private final String parent;

    /**
     * 类型
     *
     * @see MenuTypeEnum
     */
    private final Integer type;


    ProductPriceMenuEnum(String name, String alias, Integer code, AccessLinkEnum accessLinkEnum, String parent, Integer type) {
        this.name = name;
        this.alias = alias;
        this.code = code;
        this.accessLinkEnum = accessLinkEnum;
        this.parent = parent;
        this.type = type;
    }

    public static ProductPriceMenuEnum getByAlias(String alias) {
        for (ProductPriceMenuEnum productPriceMenuEnum : values()) {
            if (productPriceMenuEnum.getAlias().equals(alias)) {
                return productPriceMenuEnum;
            }
        }
        return null;
    }

    public static ProductPriceMenuEnum getByCode(Integer code) {
        for (ProductPriceMenuEnum productPriceMenuEnum : values()) {
            if (productPriceMenuEnum.getCode().equals(code)) {
                return productPriceMenuEnum;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
